package com.fbs.wowo.works.web;

import com.fbs.wowo.base.BaseController;
import com.fbs.wowo.base.Response;
import com.fbs.wowo.works.entity.Works;
import com.fbs.wowo.works.service.WorksService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("works")
@RestController
public class WorksController extends BaseController {

    @Resource
    private WorksService worksService;

    @PostMapping("insertWorks")
    public Response insertWorks(Works works){
        worksService.insertSelective(works);
        return success();
    }

    /**
     * 根据用户Id获取用户的作品列表
     */
    @GetMapping("findWorksByUserId")
    public Response findWorksByUserId(int pageNum,int pageSize,String userId){
        PageHelper.startPage(pageNum,pageSize);
        List<Works> worksList = worksService.findWorksByUserId(userId);
        PageInfo<Works> pageInfo = new PageInfo<>(worksList);
        return success(pageInfo);
    }

    /**
     * 根据类型获取个数
     * @return
     */
    @GetMapping("findTypeNum")
    public Response findTypeNum(){
        return success(worksService.findTypeNum());
    }


    /**
     * 查询审核中的列表
     * @return
     */
    @GetMapping("findWorkTheRedList")
    public Response findWorkTheRedList(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Works>  workTheRedList = worksService.findWorkTheRedList();
        PageInfo<Works> pageInfo = new PageInfo<>(workTheRedList);
        return success(pageInfo);
    }

}
